//
//  KeyboardView.m
//  DataSource
//
//  Created by yons on 15/6/21.
//  Copyright (c) 2015年 大兵布莱恩特. All rights reserved.
//

#import "KeyboardView.h"
#import "GiftModel.h"
#import "GiftBtn.h"
#import "GiftView.h"
@interface KeyboardView ()
<
UITextFieldDelegate,
UIScrollViewDelegate,
GiftViewDelegate,
GiftViewDataSource

>
{
    // 录音时间
    int timeSecond;
    
}
/**
 *  mutableString
 */
@property(nonatomic,copy)NSMutableString   *mutableAttributedString;

///  定时器
@property(nonatomic,strong)NSTimer    *timer;



@end

@implementation KeyboardView
- (id)initWithFrame:(CGRect)frame array:(NSMutableArray *)giftArr WithColor:(UIColor *)color withIslive:(BOOL)isLive
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.giftArray = giftArr;
        
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
//        {
//            [self.gifView reloadDatas];
//            
//        });
        [self.gifView reloadDatasWithBool:isLive];
        self.gifView.backgroundColor = kBlackColor;
        
        

    }
    return self;
}


-(GiftView*)gifView
{
    if (!_gifView)
    {
        // 表情键盘
        _gifView = [[GiftView alloc] initWithFrame:CGRectMake(0,self.frame.size.height - 257 - 20, XQScreenW, 257 + 20)];
        _gifView.mydelegate = self;
        _gifView.dataSource = self;
        [self addSubview:_gifView];
    }
    
    return _gifView;
}

- (NSInteger)numberOfItemsInEmojiView:(GiftView *)emojiView
{
    return self.giftArray.count;
}
/**
 *  列数
 *
 *
 *  @return 列数
 */
- (NSInteger)numberOfColumnsInWaterFlowView:(GiftView *)GiftView
{
    return 4;
}
/**
 *  行数
 *
 *  @param rows      行数
 *
 *  @return 行数
 */

- (NSInteger)GiftView:(GiftView *)GiftView numberOfRowsInRows:(NSInteger)rows
{
    return 2;
}
/**
 *  返回表情
 *
 *  @param indexPath  indexPath
 *
 *  @return  返回一个表情实例
 */
- (GiftBtn*)GiftView:(GiftView *)GiftView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row<self.giftArray.count)
    {
        GiftBtn *cell = [[GiftBtn alloc] init];
        GiftModel *model = self.giftArray[indexPath.row];
        NSLog(@"oooooooooo == %2f", model.Price);
        [cell.imageViews sd_setImageWithURL:[NSURL URLWithString:model.Img]];
        cell.imageLab.text = [NSString stringWithFormat:@"%@", model.Name];
        cell.priceLab.text = [NSString stringWithFormat:@"%2.f个金豆",model.Price * 10];
        return cell;
    }
    return nil;
}
/**
 *  每个表情的宽度
 *
 *  @param indexPath  indexPath
 *
 *  @return 返回宽度
 */
- (CGFloat)GiftView:(GiftView *)GiftView heigthForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 111;
}
/**
 *  每个表情的高度
 *
 *  @param indexPath 返回 indexPath
 *
 *  @return  返回一个表情的高度
 */
- (CGFloat)GiftView:(GiftView *)GiftView widthForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return XQScreenW / 4;
}

- (void)GiftView:(GiftView *)GiftView didSelectRowAtIndexPath:(NSInteger)selectIndex
{
    GiftModel *model = self.giftArray[selectIndex];
    
    if ([self.mydelegate respondsToSelector:@selector(keyboardViewDidSendUrl:moverImageUrl:name:price:giftID:)]) {
        [self.mydelegate keyboardViewDidSendUrl:model.Img moverImageUrl:model.MoveImg name:model.Name price:model.Price giftID:model.Id];
    }
}
- (void)GiftView:(GiftView *)GiftView didSelectNumberFlowerBtn:(NSInteger)selectIndex {
    if ([self.mydelegate respondsToSelector:@selector(keyboardViewNumberFloweBtn)]) {
        [self.mydelegate keyboardViewNumberFloweBtn];
    }
}

-(void)GiftViewdidSelectChargeBtn{
    if ([self.mydelegate respondsToSelector:@selector(keyboardViewChargeBtn)]) {
        [self.mydelegate keyboardViewChargeBtn];
    }
}
- (void)setNumberBtnTex:(NSString *)numberStr {
    [self.gifView.numberFlowerBtn setTitle:numberStr forState:UIControlStateNormal];

}
@end
